// SimNet is a Second Life(tm) sim mangement tool that was designed for Fermi Sandbox
// Copyright (C) 2011 Arthur Fermi
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To receive a copy of this license please visit http://www.gnu.org/licenses/

// SimNet - Radar

// Global Variables

default
{
    state_entry()
    {
        llSetText("", <1,1,1>, 1);
        //Setup Sensor
        llSensorRepeat("", NULL_KEY, AGENT, 96, PI, 1);
    }

    sensor(integer num_detected)
    {
        vector pos = llGetPos();
        string gstrMessage = "Scanner\n";
        integer i;
        for (i = 0; i < num_detected; i++)
        {
            if (llDetectedName(i) == llKey2Name(llGetOwner()))
            {
                // Don't add to the list
            }
            else
            {
                float diff = llVecDist(pos,llDetectedPos(i));
                integer dist = llRound(diff);
                    
                if (dist > 128)
                {
                    // Do Nothing
                }
                else
                {
                    //  Set AV List in chat range
                    gstrMessage += llDetectedName(i) + "-" + (string)dist + "M\n";
                }
            }
        }
        llMessageLinked(-2,99,gstrMessage, "");
    }
    
    no_sensor()
    {
        llMessageLinked(-2,99, "You are the only Avatar\nin the area", "");
    }
    on_rez(integer start_param)
    {
        llSetScriptState(llGetScriptName(), FALSE);
        llResetScript();    
    }
    
}
